package com.jghz.transfer.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.bstek.dorado.data.provider.Page;
import com.jghz.framework.base.BaseDao;
import com.jghz.transfer.entity.Tbplateform;

@Repository
public class WayBillDao extends BaseDao {

	public void pagingQuery(Page<Tbplateform> page, Map<String, Object> paramater) throws Exception {
		String hql = " from " + Tbplateform.class.getName() + " where 1=1 ";
		if (paramater != null) {
			if (paramater.get("compId") != null) {
				hql += " and compId = '" + paramater.get("compId") + "' ";
			}
			if (paramater.get("status") != null) {
				hql += " and status = '" + paramater.get("status") + "' ";
			}
			if (paramater.get("senderCode") != null) {
				hql += " and senderCode = '" + paramater.get("senderCode") + "' ";
			}
			if (paramater.get("sendTimeS") != null) {
				hql += " and sendTime >= '" + paramater.get("sendTimeS") + " 00:00:00' ";
			}
			if (paramater.get("sendTimeE") != null) {
				hql += " and sendTime <= '" + paramater.get("sendTimeE") + " 24:00:00' ";
			}
			if (paramater.get("consignmentDateTimeS") != null) {
				hql += " and consignmentDateTime >= '" + paramater.get("consignmentDateTimeS") + "000000' ";
			}
			if (paramater.get("consignmentDateTimeE") != null) {
				hql += " and consignmentDateTime <= '" + paramater.get("consignmentDateTimeE") + "240000' ";
			}
			if (paramater.get("goodsReceiptDateTimeS") != null) {
				hql += " and goodsReceiptDateTime >= '" + paramater.get("goodsReceiptDateTimeS") + "000000' ";
			}
			if (paramater.get("goodsReceiptDateTimeE") != null) {
				hql += " and goodsReceiptDateTime <= '" + paramater.get("goodsReceiptDateTimeE") + "240000' ";
			}
			if (paramater.get("consignor") != null) {
				hql += " and consignor like '%" + paramater.get("consignor") + "%' ";
			}
			if (paramater.get("consignee") != null) {
				hql += " and consignee like '%" + paramater.get("consignee") + "%' ";
			}

		}
		this.getHibernateDao().pagingQuery(page, hql, "select count(*) " + hql);
	}

	public List<Tbplateform> queryList(Map<String, Object> paramater) {
		String hql = " from Tbplateform where 1=1 ";
		if (paramater != null) {

			if (paramater.get("originalDocumentNumber") != null) {
				hql += " and originalDocumentNumber = '" + paramater.get("originalDocumentNumber") + "' ";
			}
			if (paramater.get("shippingNoteNumber") != null) {
				hql += " and shippingNoteNumber = '" + paramater.get("shippingNoteNumber") + "' ";
			}
			if (paramater.get("senderCode") != null) {
				hql += " and senderCode = '" + paramater.get("senderCode") + "' ";
			}

			if (paramater.get("compId") != null) {
				hql += " and compId = '" + paramater.get("compId") + "' ";
			}
			if (paramater.get("status") != null) {
				hql += " and status = '" + paramater.get("status") + "' ";
			}
		}
		List<Tbplateform> list = this.getHibernateDao().query(hql);
		return list;
	}

	public void save(Tbplateform tf) {
		getSession().save(tf);
	}

	public void update(Tbplateform tf) {
		getSession().update(tf);
	}

	public void delete(Tbplateform tf) {
		getSession().delete(tf);
	}
}
